package com.aaa.hospital.util;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.UUID;

/**
 * @author ZQ on 2022/2/10
 */
@Data
public class OSSUtil {
    private String endpoint;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;
    private String path;

    public String uploadOSS(MultipartFile headImg){
        try {
            String fileName = UUID.randomUUID().toString()+headImg.getContentType().replace("image/",".");
            OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
            InputStream inputStream = headImg.getInputStream();
            ossClient.putObject(bucketName, fileName, inputStream);
            ossClient.shutdown();
            return path+fileName;
        }catch (Exception e){
            e.printStackTrace();
        }

        return null;
    }
}
